home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / popup-menu-tester-100-c.hqx / PopupMenu Tester 1.0.0 / Tester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-03  |  2.7 KB  |  123 lines

  1. /***********************************************************************
  2.  ******* PopupMenu Tester **********************************************
  3.  ***********************************************************************
  4.  Written by Paul Celestin
  5.  
  6.  Public Domain - use at your own discretion, in any way you see fit
  7.  
  8.  This simple application demonstrates the use of a System-7 popup menu,
  9.  as well as a movable modal dialog. It doesn't do much else, but maybe
  10.  it has something to offer to someone who is new to all of this.
  11.  
  12.  941103 - 1.0.0 initial version
  13.  **********************************************************************/
  14.  
  15. #include    <Dialogs.h>
  16. #include    <Events.h>
  17.  
  18. #define        kTestDLOG    128
  19. #define        kMenu        128
  20. #define        kItemQuit    1
  21. #define        kItemPopup    2
  22. #define        kDelay        8
  23.  
  24. Boolean        gDone = false;
  25.  
  26. pascal Boolean ModalDragProc(DialogPtr inDialog, EventRecord *inEvent, short *pItem)
  27. {
  28.     Boolean done = false;
  29.  
  30.     switch (inEvent->what)
  31.     {
  32.         case mouseDown:
  33.         {
  34.             WindowPtr    myWindow;
  35.             RgnHandle    theGrayRgn;
  36.  
  37.             short thePart = FindWindow(inEvent->where,&myWindow);
  38.             if ((thePart == inDrag) && (myWindow == inDialog))
  39.             {
  40.                 theGrayRgn = GetGrayRgn();
  41.                 DragWindow(myWindow,inEvent->where,&((**theGrayRgn).rgnBBox));
  42.                 done = true;
  43.             }
  44.         }
  45.         break;
  46.         
  47.         case keyDown:
  48.         {
  49.             char typedChar = inEvent->message & 0x00FF;
  50.  
  51.             switch (typedChar)
  52.             {
  53.                 case 0x03: /* the Enter key */
  54.                 case 0x0D: /* the Return key */
  55.                 {
  56.                     short    iType,iValue;
  57.                     long    delay;
  58.                     Handle    iHandle;
  59.                     Rect    iRect;
  60.                     
  61.                     GetDItem(inDialog,kItemQuit,&iType,&iHandle,&iRect);
  62.                     if (iHandle) /* it exists */
  63.                     {
  64.                         iValue = !GetCtlValue((ControlHandle)iHandle);
  65.                         HiliteControl((ControlHandle)iHandle,1);
  66.                         Delay(kDelay,&delay);
  67.                         HiliteControl((ControlHandle)iHandle,0);
  68.                     }
  69.                     done = true;
  70.                     gDone = true;
  71.                 }
  72.                 break;
  73.             }
  74.         }
  75.         break;
  76.  
  77.         }
  78.     return done;
  79. }
  80.  
  81. main()
  82. {
  83.     short        itemType, itemHit, myChoice;
  84.     Str255        myTitle;
  85.     DialogPtr    myDialog;
  86.     Handle        myPopHandle;
  87.     MenuHandle    myMenu;
  88.     Rect        myPopRect;
  89.  
  90.     InitGraf(&qd.thePort);
  91.     InitFonts();
  92.     InitWindows();
  93.     InitMenus();
  94.     TEInit();
  95.     InitDialogs(0);
  96.     InitCursor();
  97.  
  98.     myDialog = GetNewDialog(kTestDLOG,0,(WindowPtr) -1);
  99.     if (myDialog)
  100.     {
  101.         while (!gDone)
  102.         {
  103.             ModalDialog(ModalDragProc,&itemHit);
  104.             switch(itemHit)
  105.             {
  106.                 case kItemQuit:
  107.                     gDone = true;
  108.                 break;
  109.  
  110.                 case kItemPopup:
  111.                     /* user selected the popup menu, let's show selection in title bar */
  112.                     GetDItem(myDialog,kItemPopup,&itemType,&myPopHandle,&myPopRect);
  113.                     myChoice = GetCtlValue((ControlHandle)myPopHandle);
  114.                     myMenu = GetMenu(kMenu);
  115.                     GetItem(myMenu,myChoice,myTitle);
  116.                     SetWTitle(myDialog,myTitle);
  117.                 break;
  118.             }
  119.         }
  120.         DisposeDialog(myDialog);
  121.     }
  122. }
  123.